﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Http.ModelBinding;

namespace WS1.Models
{
   public class AppResult
    {
        public bool IsSuccess { get; set; }
        public string Message { get; set; }
        public AppResult()
        {
            IsSuccess = true;
        }
       
        public void ModelError(ModelStateDictionary msd)
        {
            var sb = new StringBuilder();
            foreach (var state in msd.Values)
            {
                foreach(var error in state.Errors)
                {
                    sb.AppendLine($"错误信息：{error.ErrorMessage}");
                    if (error.Exception != null)
                    {
                        sb.AppendLine($"异常信息：{error.Exception.Message}");
                    }
                }
            }
            IsSuccess = false;
           Message= sb.ToString().TrimEnd();
        }

    }
    
        
    public class AppResult<T> : AppResult
    {
       public  T Data { get; set; }
    }

}